package org.mydba.info;

/**
 * Represents ResultSet execution statistics.
 *
 * @since 1.0
 */
public class ResultSetStatistic {
    private int numberOfNext=1;
    private long startTimeNs;
    private long totalNextDuration;

    public ResultSetStatistic(final long startTimeNs, final long initialNextDuration) {
        this.startTimeNs = startTimeNs;
        this.totalNextDuration = initialNextDuration;
    }

    public int getNumberOfNext() {
        return numberOfNext;
    }

    public long getStartTimeNs() {
        return startTimeNs;
    }

    public long getTotalNextDuration() {
        return totalNextDuration;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        ResultSetStatistic that = (ResultSetStatistic) o;

        if (totalNextDuration != that.totalNextDuration) {
            return false;
        }
        if (numberOfNext != that.numberOfNext) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = numberOfNext;
        result = 31 * result + (int) (totalNextDuration ^ (totalNextDuration >>> 32));
        return result;
    }

    public void update(final long nextDuration) {
        numberOfNext++;
        totalNextDuration += nextDuration;
    }
}
